package com.wanlian.common;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class CoderUtil
{

    public static String encode(String text)
    {
        try
        {
            Base64.Encoder encoder = Base64.getEncoder();
            byte[] textByte;
            textByte = text.getBytes("UTF-8");
            String encodedText = encoder.encodeToString(textByte);
            return encodedText;
        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
            return "";
        }
    }

    public static String decode(byte[] encodedText)
    {
        final Base64.Decoder decoder = Base64.getDecoder();
        try
        {
            return new String(decoder.decode(encodedText), "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {

            e.printStackTrace();
            return "";
        }

    }
}
